<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/view/common/common.jsp"%>
<style>
.none {
	display: none;
}
</style>
<div class="modal-dialog modal-lg" role="document">
	<div class="modal-content">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-label="Close">
				<span aria-hidden="true">&times;</span>
			</button>
			<h4 class="modal-title text-primary" id="myModalLabel">活动信息编辑</h4>
		</div>
		<div class="modal-body">
			<div class="container-fluid">
				<form action="<c:url value='/activity/edit.json'/>" name="editForm" enctype="multipart/form-data"
							class="form-horizontal"  id="editForm" method="post">
				<div class="row">				
					<div class="col-md-12 col-xs-12">
					<div class="panel panel-primary">
							<div class="panel-heading">
								基本信息
							</div>
							<div class="panel-body">	
						
							<input type="hidden" name="activityId" value="${parameter.entity.activityId}">

							<div class="form-group">
								<label for="name" class="col-sm-2 control-label">活动名称</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="name" tabIndex="13"
										name="name" value="${parameter.entity.name}"
										placeholder="活动名称">
								</div>
								<div class="col-md-4 col-xs-4 text-error"></div>
							</div>


							<div class="form-group">
								<label for="code" class="col-sm-2 control-label">活动编号</label>
								<div class="col-sm-8">
									<input type="text" class="form-control" id="code" tabIndex="13"
										name="code" value="${parameter.entity.code}"
										placeholder="活动编号是唯一的,是每个活动的唯一标识，不可重复(请记住)">
								</div>
								<div class="col-md-4 col-xs-4 text-error"></div>
							</div>


								<div class="form-group">
									<label for="beginTime" class="col-sm-2 control-label">活动开始时间</label>
									<div class="col-sm-8">
										<input type="date" class="form-control" id="beginTime" tabIndex="13"
											   name="beginTime" value="${parameter.entity.beginTime}"
											   placeholder="活动开始时间：2018-08-08">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="endTime" class="col-sm-2 control-label">活动结束时间</label>
									<div class="col-sm-8">
										<input type="date" class="form-control" id="endTime" tabIndex="13"
											   name="endTime" value="${parameter.entity.endTime}"
											   placeholder="活动结束时间:2018-08-16">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<div class="form-group">
									<label for="rule" class="col-sm-2 control-label">活动规则说明</label>
									<div class="col-sm-8">
										<input type="textarea" class="form-control" id="rule"
											   name="rule" value="${parameter.entity.rule}"
											   placeholder="规则说明">
									</div>
									<div class="col-md-4 col-xs-4 text-error"></div>
								</div>

								<%--<div class="form-group">--%>
									<%--<label for="lotteryCode" class="col-sm-2 control-label">活动抽奖码</label>--%>
									<%--<div class="col-sm-8">--%>
										<%--<input type="text" class="form-control" id="lotteryCode" tabIndex="13"--%>
											   <%--name="lotteryCode" value="${parameter.entity.lotteryCode}"--%>
											   <%--placeholder="抽奖码">--%>
									<%--</div>--%>
									<%--<div class="col-md-4 col-xs-4 text-error"></div>--%>
								<%--</div>--%>

								<%--<div class="form-group">--%>
									<%--<label for="isPublish" class="col-sm-2 control-label">是否发布</label>--%>
									<%--<div class="col-sm-8">--%>
										<%--<input type="text" class="form-control" id="isPublish" tabIndex="13"--%>
											   <%--name="isPublish" value="${parameter.entity.isPublish}"--%>
											   <%--placeholder="是or否">--%>
									<%--</div>--%>
									<%--<div class="col-md-4 col-xs-4 text-error"></div>--%>
								<%--</div>--%>

						</div>
						</div>
					</div>

				</div>
				</form>
			</div>
		</div>
		<div class="modal-footer">
			<div class="form-group">
				<div class="col-md-6 col-xs-12">
					<button type="button" class="btn btn-default btn-block quitBtn" tabIndex="26"
						id="quitBtn" data-dismiss="modal" name="quitBtn" value="login"
						tabindex="4" data-loading-text="正在返回......">
						<span class="glyphicon glyphicon-remove-sign">&nbsp;</span>关闭
					</button>
				</div>
				<div class="col-md-6 col-xs-12">
					<button type="button" class="btn btn-success btn-block" form="editForm" tabIndex="27"
						id="saveBtn" name="saveBtn" value="saveBtn" tabindex="4"
						data-loading-text="正在提交......">
						<span class="glyphicon glyphicon-save">&nbsp;</span>保存
					</button>
				</div>
			</div>
		</div>
	</div>
</div>


<jsp:include page="/WEB-INF/view/common/form.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		init();
		initRmLevel();
		rmLevel();
	});
	
	function rmLevel(){
		$(":radio").click(function(){
			  var type=$(this).val();
			  hideInput(type);
		});
	}
	
	function initRmLevel(){
		var type=$("input:radio:checked").val();
		if(type!=undefined){
			hideInput(type);
		}
		}
	
	function hideInput(type){
		  $("#levelTable tr.lc").each(function (){
				if($(this).attr("tag")!=type){
				$(this).find("input").attr("disabled","disabled"); 
				$(this).css("display","none");
				}else{
					$(this).find("input").removeAttr("disabled"); 
					$(this).css("display","");
				}
		  });
	}
	

	function init() {
		//$("#editName").focus().select();
		var btn = null;
		$("#editForm").validate({submitHandler : function(form) {
						$(form).ajaxSubmit({
									beforeSubmit : function(arr, $form, options) {
										btn.button("loading");
									},
									success : function(responseText,
											statusText, xhr, $form) {
										var m = $.parseJSON(xhr.responseText);
										btn.button("reset");
										if(m.flag=="0"){
											alert("保存成功!");
										$(".quitBtn").click();
											$("#search").click();
                                            location.reload();
                                        }else{
											alert("保存失败");
										}
									},
									error : function(xhr, textStatus,
											errorThrown) {
										var m = $.parseJSON(xhr.responseText);
										btn.button("reset");
										alert("保存失败");
									}
								});
					},
					rules : {
						name : {
							required : true
						},
						code:{
							required: true
						},
                        beginTime:{
                            required: true
                        },
                        endTime:{
                            required: true
                        },
                        rule:{
                            required: true
                        }
						// lotteryCode:{
						// 	required: true
						// }
					},
					onkeyup : false,
					messages : {
						name : {
							required : "活动名称必须填写"
						},
						code:{
							required:"活动编号必须填写"
						},
                        beginTime:{
                            required:"活动开始时间必须填写"
                        },
                        endTime:{
                            required:"活动结束时间必须填写"
                        },
						rule:{
                            required:"活动规则必须填写"
                        }
						// lotteryCode:{
						// 	required:"抽奖码必须设置"
						// }
					},
					focusInvalid : true,
					errorClass : "text-danger",
					validClass : "valid",
					errorElement : "small",
					errorPlacement : function(error, element) {
						error.appendTo(element.closest("div.form-group")
								.children("div.text-error"));
					}
				});
		$("#editForm").find("input[type='checkbox']").change(function(e){
			var $t=$(this);
			var next=$t.next("input[type='hidden']");
			$t.prop("checked")?next.val(1):next.val(0);
		});
		

	
		
		$("#saveBtn").click(function(e) {
			btn = $(this).button();
			$(document.forms["editForm"]).submit(); 
			/* $('#uploadModal').modal({
				backdrop : "static"
			});
			
			setInterval("getProgress()",1000); */
		});
	
		
	}

	
</script>
